Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",width:40}),
{header:'债项ID',dataIndex:'debtNo',hidden:true},
{header:'客户ID',dataIndex:'guarantorId',hidden:true},
{header:'客户名称',dataIndex:'custName',hidden:true},
{header:'债项名称',dataIndex:'debtName',width:100},
{header:'保证人名称',dataIndex:'guarantorName',width:100},
{header:'保证类型',dataIndex:'guarantyType',width:100, hidden:true},
{header:'保证金额(元)',dataIndex:'guarantySum',width:100},
{header:'保证起始日',dataIndex:'startDate',width:100},
{header:'保证到期日',dataIndex:'endDate',width:100},
{header:'保证人与借款人之间关系',dataIndex:'guarantorRelative',width:100},
{header:'保证人规模',dataIndex:'guarantorScope',width:100},
{header:'保证人还款金额',dataIndex:'guarantorPaySum',width:100,hidden:true},
]); 
var ds=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'obligation/listDebtGuarantor.do',
method:'POST'
}), 
reader:new Ext.data.JsonReader({idProperty: 'id'},[
{name:'debtNo',mapping:'gid.debtNo'}, 
{name:'guarantorId',mapping:'gid.guarantorId'}, 
{name:'custName'}, 
{name:'debtName'}, 
{name:'guarantorName'}, 
{name:'guarantyType'}, 
{name:'guarantySum'}, 
{name:'startDate'}, 
{name:'endDate'}, 
{name:'guarantorRelative'}, 
{name:'guarantorScope'},
{name:'guarantorPaySum'}
]) 
}); 
ds.load({params:{start:0,limit:10}}); 

var addGuarantyTypeLevelOneStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showGuarantyTypeLevelOne.do',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addGuarantyTypeLevelTwoStore=new Ext.data.Store({  
		reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
	])
}); 

var addGuarantyStyleStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GuarantyStyle',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addGuaranteeStyleStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GuaranteeStyle',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addGuarantorStyleStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GuarantorStyle',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addGuarantorTypeStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=GuarantorType',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addIsOurCustStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=YesNo',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad:true
}); 

var addCustTypeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CustType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]) ,
autoLoad:true
}); 

//var addGuarantyFormStore=new Ext.data.Store({ 
//	proxy:new Ext.data.HttpProxy({
//	url:'showType.do?type=GuarantyForm',
//	method:'GET'
//	}), 
//	reader:new Ext.data.JsonReader({ },[
//	{name:'name'}, 
//	{name:'code'}
//	]) ,
//	autoLoad:true
//}); 
//
//var addGuaranteeFormStore=new Ext.data.Store({ 
//	proxy:new Ext.data.HttpProxy({
//	url:'showType.do?type=GuaranteeForm',
//	method:'GET'
//	}), 
//	reader:new Ext.data.JsonReader({ },[
//	{name:'name'}, 
//	{name:'code'}
//	]) ,
//	autoLoad:true
//}); 

var addGuarantyRelativeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=GuarantyRelativeType',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
])  ,
autoLoad:true
}); 

var addCustScopeStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=CustScope',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
])  ,
autoLoad:true
}); 

var addCustListStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showCustList.do',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
])  ,
autoLoad:true
}); 

var addGuarantorListStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showGuarantorList.do',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	])  ,
	autoLoad:true
}); 

var addExtRatOrgStore=new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'showType.do?type=ExtRatOrg',
method:'GET'
}), 
reader:new Ext.data.JsonReader({ },[
{name:'name'}, 
{name:'code'}
]),
autoLoad:true
}); 



var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"debtGuarantee_list", 
stripeRows:true,//斑马线效果
title:"当前债项-保证信息列表", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
		forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 10,   
                store: ds,   
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据"   
            }),
 tbar: [
 {text:'新增',id: 'btnAdd'},
 '-',
 {text:'查看/编辑',handler:checkMyCustomer},
 '-',
 {text:'删除',handler:deleteCustomer}
 ]              
});

//新增客户表单
addForm = new Ext.form.FormPanel({ 
id: 'addCustomerForm', 
width: 650, 
height: 300, 
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 140, 
items: 
[ { xtype: 'fieldset', 
title: '保证信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 

{
	layout:"column",
items:[
       
    {columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
	           items : [	{ 
		xtype: 'combo', 
 	id : "guarantorId",
 	name: 'guarantorId', 
              store :addGuarantorListStore,
              fieldLabel: '保证人名称',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              mode:'local', 
              emptyText : '请选择保证人...',
              //editable: false,
              triggerAction : 'all',
              forceSelection:true, 
			  typeAhead:true, 
              selectOnFocus : true,
              hiddenName:'guarantorId',
             
              listeners:{  	        	   
	        	   select : function(combo, record,index){
						Ext.Ajax.request({
							  url:'obligation/getGuarantor.do',
							  params : {guarantorId : combo.value},
							  method:'POST',
							  success:function(response){
								  //alert(response.responseText);
								  var json = Ext.util.JSON.decode(response.responseText);
								  Ext.getCmp("guarantorScope").setValue(json.custScope);
								  Ext.getCmp("guarantorId").setValue(json.guarantorId);
								  Ext.getCmp("bdcreditLevel").setValue(json.creditLevel);
								  Ext.getCmp("bdcreditDate").setValue(json.creditDate);
								  Ext.getCmp("isOurCust").setValue(json.isOurCustomer);
								  
								//  addCustListStore.reload();
								  //alert(json.custScope);
								   
							  },failure:function(){
							    Ext.MessageBox.alert("提示", "获取客户信息失败！"); 
							  }
						});
					} 
	           }
	}]},
//	    {columnWidth : .5, // 该列有整行中所占百分比
//           layout : "form",
//	           items : [	{ 
//	        	xtype: 'textfield', 
//	   			id: 'guarantorId',
//	   			name: 'guarantorId', 
//	   			fieldLabel: '保证人客户号',
//	   			width: 150,
//             
//	}]},
//	{ columnWidth : .2, // 该列有整行中所占百分比
//        layout : "form",
//	           items : [
//	{
//	
//				xtype: 'button',
//				id: 'inputBtn', 
//				name: 'inputBtn', 
//				text: '引入保证人',
//				handler: function( ){
//					if(Ext.getCmp('guarantorId').getValue() == ''){
//						Ext.MessageBox.alert("提示","请先填写左方“保证人客户号”");
//					}
//					else{
//						Ext.Ajax.request({
//						  url:'customer/getGeneral.do?isGuarantor=1',
//						  params : {custId : Ext.getCmp('guarantorId').getValue()},
//						  method:'POST',
//						  success:function(response){
//							  //alert(response.responseText);
//							  var json = Ext.util.JSON.decode(response.responseText);
//							  if(json.custId == '')Ext.MessageBox.alert("提示","不存在该客户");
//							  else{
//								  Ext.getCmp("guarantorName").setValue(json.custName);
//								  Ext.getCmp("guarantorScope").setValue(json.custScope);
//								  Ext.getCmp("bdcreditLevel").setValue(json.bdcreditLevel);
//								  Ext.getCmp("bdcreditDate").setValue(json.bdcreditDate);
//							  }
//							  
//							//  addCustListStore.reload();
//							  //alert(json.custScope);
//							   
//						  },failure:function(){
//						    Ext.MessageBox.alert("提示", "不存在该客户"); 
//						  }
//						});
//					}
//	}
//   
//	}]} ,
	{ columnWidth : .3, // 该列有整行中所占百分比
        layout : "form",
	           items : [
	{
	
				xtype: 'button',
				id: 'acBtn', 
				name: 'acBtn', 
				text: '点此新增一保证人',
				handler: addGuarantor
   
	}]} 
]}, {
	layout:"column",
	items:[{
	   columnWidth : .5, // 该列有整行中所占百分比
	   layout : "form",
	   items : [	{ 
			xtype: 'textfield', 
			id: 'bdcreditLevel',
			name: 'bdcreditLevel', 
			fieldLabel: '违约前最后一次保证人信用评级', 
			readOnly:true,
			width: 150,
	}]},
	{ columnWidth : .5, // 该列有整行中所占百分比
      layout : "form",
	  items : [{
		  	xtype: 'textfield', 
			id: 'bdcreditDate',
			name: 'bdcreditDate', 
			fieldLabel: '违约前最后一次保证人信用评级日期', 
			readOnly:true,
			width: 150, 	   
	}]} 
]}, {
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
			           items : [	{ 
		xtype: 'textfield', 
		id: 'guarantySum',
		name: 'guarantySum', 
		fieldLabel: '保证金额（元）', 
		emptyText: '必填', 
		allowBlank: false,  
		blankText: '保证金额不能为空', 
	 	regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 	regexText:'只能输入整数或小数！' ,   
		width: 150,
		}]},
		{ columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
		           items : [
		{      
			
			xtype: 'textfield', 
					id: 'guarantorPaySum',
					name: 'guarantorPaySum', 
					fieldLabel: '保证人还款金额（元）', 
					allowBlank: true,  
					width: 150,
					regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
	 				regexText:'只能输入整数或小数！' ,
		}]} 
	]}, 

	{
		layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [
	        	   {    
	        	xtype: 'combo', 
	        	id : "guarantorStyle",
	              store :addGuarantorStyleStore,
	              fieldLabel: '保证人类型',
	              valueField : 'code',
	              displayField : 'name',
	              typeAhead : true,
	              width: 150,
	              mode:'remote', 
	              emptyText : '请选择保证人类型...',
	      			allowBlank: false,  
	    		blankText: '保证人类型不能为空', 
	              editable: false,
	              triggerAction : 'all',
	              selectOnFocus : true,
	              hiddenName:'guarantorStyle',
				}
	           ]},
	           
	           { columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [
	        	 {
	        		 xtype: 'combo', 
	    		     id : "isOurCust",
	     		 store :addIsOurCustStore,
	              fieldLabel: '是否为我行客户',
	              valueField : 'code',
	              displayField : 'name',
	              typeAhead : true,
	              width : 150,
	              mode:'remote', 
	              emptyText : '请选择是否为我行客户...',
	              allowBlank: false,  
	              blankText: '是否为我行客户不能为空', 
	              editable: false,
	              triggerAction : 'all',
	              selectOnFocus : true,
	              hiddenName:'isOurCust',       
			}	   
	      ]} 
	]},	
	
{
	layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	   { 
        		   
        		     xtype: 'combo', 
        		     id : "guarantyStyle",
              store :addGuarantyStyleStore,
              fieldLabel: '保证方式',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              mode:'remote', 
              emptyText : '请选择保证方式...',
              allowBlank: false,  
              blankText: '保证方式不能为空', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guarantyStyle',
			}
           ]},
           
           { columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	 {
        		 xtype: 'combo', 
    		     id : "guaranteeStyle",
     		 store :addGuaranteeStyleStore,
              fieldLabel: '保证担保形式',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width : 150,
              mode:'remote', 
              emptyText : '请选择保证担保形式...',
              allowBlank: false,  
              blankText: '保证担保形式不能为空', 
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guaranteeStyle',
              
		}
        	   
        	   ]} 
]},


{
	layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	   { 
        		   xtype: 'combo', 
		 id : "guarantorScope",
              store :addCustScopeStore,
              fieldLabel: '保证人规模',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              mode:'remote', 
              emptyText : '请选择保证人规模...',
              editable: false,
              readOnly:false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guarantorScope',

				}
           ]},
           
           { columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	 {
        			xtype: 'datefield',
				id: 'startDate', 
				name: 'startDate', 
				fieldLabel: '保证起始日',  
				allowBlank: true,  
				width:150,
				allowBlank: false,  
	            blankText: '保证起始日不能为空', 
				editable:false,
				format : 'Y-m-d'
			}
        	   
        	   ]} 
]}, 



{
	layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	   { 
				   xtype: 'combo', 
		 id : "guarantorRelative",
              store :addGuarantyRelativeStore,
              fieldLabel: '保证人与借款人关系',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              width: 150,
              mode:'remote', 
              emptyText : '保证人与借款人关系',
              editable: false,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'guarantorRelative',
				}
           ]},
           
           { columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [
        	{ 
        		 xtype: 'datefield',
 				id: 'endDate', 
 				name: 'endDate', 
 				fieldLabel: '保证到期日',  
 				allowBlank: true,  
 				width:150,
 				allowBlank: false,  
	            blankText: '保证到期日不能为空', 
 				editable:false,
 				format : 'Y-m-d'
			}
        	   ]} 
]},

{ layout : "form",
           items : [{
xtype: 'hidden', 
 id : "debtNo",
              fieldLabel: '债项ID',
              allowBlank: true
}]},

] 
}]
});





//新增用户窗口 
addWin = new Ext.Window({ 
id: 'addCustomerWin', 
title: '保证信息', 
width: 670, 
height: 320, 
//背景遮罩 
modal: true, 
//重置大小 
resizable: false, 
//当关闭按钮被点击时执行的动作 
closeAction: 'hide', 
plain: true, 
buttonAlign: 'right', 
items:addForm, 
buttons: 
[  
{ text: '保存', id: 'btnSubmit' } ,
{ text: '关闭', handler: function() { Ext.getCmp('addCustomerWin').hide(); } }

] 
});

//新增客户表单
addGuarantorForm = new Ext.form.FormPanel({ 
id: 'addGuarantorForm', 
width: 370, 
height: 500,
//样式 
bodyStyle: 'margin:3px 3px 3px 3px', 
frame: true, 
xtype: 'filedset', 
labelWidth: 100, 
items: 
[ { xtype: 'fieldset', 
title: '客户信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{xtype: 'combo', 
id : "guarantorType",
  store :addGuarantorTypeStore,
  fieldLabel: '保证人类型',
  valueField : 'code',
  displayField : 'name',
  typeAhead : true,
  width: 200,
  mode:'remote', 
  emptyText : '请选择保证人类型...',
  allowBlank: false,  
  blankText: '保证人类型不能为空', 
  editable: false,
  triggerAction : 'all',
  selectOnFocus : true,
  hiddenName:'guarantorType',
  listeners:{  	        	   
	   select : function(combo, record,index){
		   		//alert(combo.value);
		   		if(combo.value == "01"){
		   			Ext.getCmp('OrganizationID').hide();
		   			Ext.getCmp('BusiLicenseID').hide();
		   			Ext.getCmp('custType').hide();
		   			Ext.getCmp('custScope').hide();
		   			Ext.getCmp('creditLevel').hide();
		   			Ext.getCmp('creditDate').hide();
		   			Ext.getCmp('CustName').show();
		   			Ext.getCmp('CustNo').show();
		   			Ext.getCmp('isOurCustomer').show();
		   			Ext.getCmp('identityCardId').show();
		   			Ext.getCmp('personalAsset').show();
		   			Ext.getCmp('personalDebt').show();
		   			Ext.getCmp('annualIncome').show();	
		   		}else{
		   			Ext.getCmp('OrganizationID').show();
		   			Ext.getCmp('BusiLicenseID').show();
		   			Ext.getCmp('custType').show();
		   			Ext.getCmp('custScope').show();
		   			Ext.getCmp('creditLevel').show();
		   			Ext.getCmp('creditDate').show();
		   			Ext.getCmp('CustName').show();
		   			Ext.getCmp('CustNo').show();
		   			Ext.getCmp('isOurCustomer').show();
		   			Ext.getCmp('identityCardId').hide();
		   			Ext.getCmp('personalAsset').hide();
		   			Ext.getCmp('personalDebt').hide();
		   			Ext.getCmp('annualIncome').hide();
		   		}
		   }
	   }
  
  
  
}
  ,
  { 
	xtype: 'textfield', 
	id:'CustNo',
	name: 'CustNo', 
	fieldLabel: '客户号', 
//	emptyText: '必填', 
//	blankText: '角色编号不能为空', 
//	allowBlank: false, 
	width:200,
	maxLength: 40, 
	maxLengthText: '角色不能超过40个字符', 
	hidden:true,
	},
{ 
xtype: 'textfield', 
id:'CustName',
name: 'CustName', 
fieldLabel: '客户名称', 
emptyText: '必填', 
blankText: '角色名称不能为空', 
allowBlank: false, 
maxLength: 50, 
width:200, 
maxLengthText: '角色不能超过50个字符', 
hidden:true,	
}, 

{ 
xtype: 'textfield',
id: 'OrganizationID', 
name: 'OrganizationId', 
fieldLabel: '组织机构代码', 
width:200,  
hidden:true
},

{ 
xtype: 'textfield', 
id: 'BusiLicenseID',
name: 'BusiLicenseId', 
fieldLabel: '营业执照代码', 
width:200,
hidden:true,
},

{ 
	xtype: 'textfield', 
	id: 'identityCardId',
	name: 'identityCardId', 
	fieldLabel: '身份证号', 
	width:200,
	hidden:true,
},

{      
	xtype: 'textfield', 
			id: 'personalAsset',
			name: 'personalAsset', 
			fieldLabel: '个人资产总额（元）', 
			allowBlank: true,  
			width: 200,
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
				regexText:'只能输入整数或小数！' ,
			hidden:true,
},

{      
	xtype: 'textfield', 
			id: 'personalDebt',
			name: 'personalDebt', 
			fieldLabel: '个人负债总额（元）', 
			allowBlank: true,  
			width: 200,
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			regexText:'只能输入整数或小数！' ,
			hidden:true,
},

{      
	xtype: 'textfield', 
			id: 'annualIncome',
			name: 'annualIncome', 
			fieldLabel: '年收入（元）', 
			allowBlank: true,  
			width: 200,
			regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
			regexText:'只能输入整数或小数！' ,
			hidden:true,
},


{ 
xtype: 'combo', 
 	id : "custType",
              store :addCustTypeStore,
              fieldLabel: '客户种类',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              mode:'remote', 
              emptyText : '请选择客户种类...',
              editable: false, 
  			  width:200,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'custType',
              hidden:true,
},
{ 
xtype: 'combo', 
 	id : "custScope",
              store :addCustScopeStore,
              fieldLabel: '保证人规模',
              valueField : 'code',
              displayField : 'name',
              typeAhead : true,
              mode:'remote', 
              emptyText : '请选择保证人规模...',
              editable: false, 
  			  width:200,
              triggerAction : 'all',
              selectOnFocus : true,
              hiddenName:'custScope',
              hidden:true,
},

{ layout : "form",
           items : [{
			xtype: 'textfield',
			id: 'creditLevel', 
			name: 'creditLevel', 
			fieldLabel: '最后一次信用评级',  
			allowBlank: true,  
			width:200, 
			hidden:true,
}]},

{ 
layout : "form",
	items : [{
			xtype: 'datefield',
			id: 'creditDate', 
			name: 'creditDate', 
			fieldLabel: '最后一次信用评级时间',  
			allowBlank: true, 
			width:200,
			format : 'Y-m-d',
			hidden:true,
}]} ,

{ 
	layout : "form",
		items : [{
			 xtype: 'combo', 
		     id : "isOurCustomer",
		  store :addIsOurCustStore,
          fieldLabel: '是否为我行客户',
          valueField : 'code',
          displayField : 'name',
          typeAhead : true,
          width : 200	,
          mode:'remote', 
          emptyText : '请选择是否为我行客户...',
          allowBlank: false,  
          blankText: '是否为我行客户不能为空', 
          editable: false,
          triggerAction : 'all',
          selectOnFocus : true,
          hiddenName:'isOurCustomer',   
          hidden:true,
}]} ,

] 
}]
});

//新增用户窗口 
addGuarantorWin = new Ext.Window({ 
id: 'addGuarantorWin', 
title: '新增保证人', 
width: 380, 
height: 400, 
//背景遮罩 
modal: true, 
//重置大小 
resizable: false, 
//当关闭按钮被点击时执行的动作 
closeAction: 'hide', 
plain: true, 
buttonAlign: 'right', 
items:addGuarantorForm, 
buttons: 
[  
{ text: '保存', id: 'btnGuarantorSubmit' } ,
{ text: '关闭', handler: function() { Ext.getCmp('addGuarantorWin').hide(); } }

] 
});


function addRoleFunction() {

	var addForm = Ext.getCmp("addCustomerForm");
	Ext.getCmp("acBtn").show();
	 

if(addForm.form.isValid()){
	 addForm.form.doAction('submit', { 

                    url : 'obligation/addDebtGuarantee.do', 
 
                    method : 'post', 
 
                       
                       success : function() { 

                     //  alert(111);
                         
                        Ext.getCmp('myCustomers').store.reload();
						Ext.getCmp("addCustomerWin").hide(); 
                       grid.store.reload();
                     Ext.Msg.alert('提示', '保存成功！'); 
 
                       }, 
                        failure : function(form, action) { 
		
                           Ext.Msg.alert('提示', '该保证人已存在，请重新选择！'); 
 
                        } 
                    });  
	
             }
 }

//添加按钮单击事件 
function btnAddClick() { 
Ext.getCmp("addCustomerWin").show();
addForm.getForm().getEl().dom.reset();
Ext.getCmp("addCustomerWin").hide(); 


//addCustListStore.reload();
Ext.getCmp('acBtn').show(); 
//Ext.getCmp("guarantorId").enable();
Ext.getCmp("guarantorId").readOnly = false;
Ext.getCmp("addCustomerWin").buttons[0].handler = addRoleFunction; 
Ext.getCmp("addCustomerWin").show(); 
}; 

//新增按钮 
var addUserBtn = Ext.getCmp('btnAdd'); 
addUserBtn.on('click', btnAddClick); 

//删除客户
function deleteCustomer(){
var grid = Ext.getCmp('myCustomers'); 
if (grid.getSelectionModel().getSelections()[0] == undefined) { 
Ext.Msg.alert("提示", "请选中要删除的项！"); 
} 
else{
Ext.MessageBox.confirm('提示', '确实要删除所选中项吗？', deleteConfirm);
}
}

function deleteConfirm(btn){
if (btn == 'yes') {
 Ext.Ajax.request({
  url:'obligation/deleteDebtGurantor.do',
  params : {guarantorId : grid.getSelectionModel().getSelections()[0].data.guarantorId},
  method:'POST',
  success:function(){
   Ext.MessageBox.alert("提示","删除成功！");
   Ext.getCmp('myCustomers').store.reload(); 
  },failure:function(){
    Ext.MessageBox.alert("提示", "删除失败！"); 
  }
});
}
}

function viewMyCustomer(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要查看的客户！"); 
	}
	
	
}

function checkMyCustomer(){
if (grid.getSelectionModel().getSelections()[0] == undefined) { 
Ext.Msg.alert("提示", "请选中要查看的项！"); 
}
else{
	var guarantorId = grid.getSelectionModel().getSelections()[0].data.guarantorId;
	//alert(guarantorId);
	
	Ext.getCmp('addCustomerForm').getForm().reset(); 
	Ext.getCmp("acBtn").hide();
	Ext.getCmp("addCustomerWin").buttons[0].handler = editAddressFunction; 
	
           Ext.Ajax.request({
url:'obligation/getDebtGuarantee.do',
params : { guarantorId: grid.getSelectionModel().getSelections()[0].data.guarantorId},
method:'POST',
   success:function(response){
	//alert(response.responseText);
 	var addJSON = Ext.util.JSON.decode(response.responseText);
 	
// 	addGuarantyTypeLevelTwoStore.proxy =new Ext.data.HttpProxy({
//		url:'showGuarantyTypeLevelTwo.do?LevelOneId='+addJSON.guarantyTypeLevelOne,
//		method:'GET'
//		}); 
// 	addGuarantyTypeLevelTwoStore.load();
 	
  	Ext.getCmp("debtNo").setValue(addJSON.gid.debtNo);  
	Ext.getCmp("guarantorId").setValue(addJSON.gid.guarantorId);
//	Ext.getCmp("guarantorId").disable();
	Ext.getCmp("guarantorId").readOnly = true;
//	Ext.getCmp("guarantorName").setValue(addJSON.guarantorName);
//  	Ext.getCmp("guarantyTypeLevelOne").setValue(addJSON.guarantyTypeLevelOne);
//  	Ext.getCmp("guarantyTypeLevelTwo").setValue(addJSON.guarantyTypeLevelTwo);
	Ext.getCmp("guarantorStyle").setValue(addJSON.guarantorStyle);
	Ext.getCmp("guarantyStyle").setValue(addJSON.guarantyStyle);
	Ext.getCmp("guaranteeStyle").setValue(addJSON.guaranteeStyle);
	Ext.getCmp("isOurCust").setValue(addJSON.isOurCust);
  	Ext.getCmp("guarantySum").setValue(addJSON.guarantySum);
   	Ext.getCmp("startDate").setValue(addJSON.startDate);
   	Ext.getCmp("endDate").setValue(addJSON.endDate);
   	Ext.getCmp("guarantorRelative").setValue(addJSON.guarantorRelative);
	Ext.getCmp("guarantorScope").setValue(addJSON.guarantorScope);
	Ext.getCmp("guarantorScope").readOnly = true;
	Ext.getCmp("guarantorPaySum").setValue(addJSON.guarantorPaySum);
	Ext.getCmp("guarantorId").setValue(addJSON.gid.guarantorId);
	Ext.getCmp("bdcreditLevel").setValue(addJSON.bdcreditLevel);
	Ext.getCmp("bdcreditDate").setValue(addJSON.bdcreditDate);
	Ext.getCmp("acBtn").hide();
//	Ext.getCmp("inputBtn").hide();

	Ext.getCmp("addCustomerWin").show();
	
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
}); 
}
}


//编辑地址
function editAddressFunction(){
	
	var addForm = Ext.getCmp("addCustomerForm");
if(addForm.form.isValid()){
	 addForm.form.doAction('submit', { 

                    url : 'obligation/editDebtGuarantee.do', 
 
                    method : 'post', 
 
                       
                       success : function() { 

                       
                       Ext.getCmp('myCustomers').store.reload();
                       Ext.Msg.alert('提示', '保存成功！'); 
 
                       }, 
                        failure : function(form, action) { 

                           Ext.Msg.alert('提示', '保存失败！'); 
 
                        } 
                    }); 
                    }
}

function rowdblclickFn(grid, rowIndex, e){//双击事件  
             var row = grid.getStore().getAt(rowIndex); 
			 var debtNo = grid.getSelectionModel().getSelections()[0].data.debtNo;
             Ext.Ajax.request({
  url:'checkRequest.do',
  method:'GET',
  success:function(){
  window.location.href="obligation/viewDebtDetail.do?debtNo="+debtNo;
  },failure:function(){
    Ext.MessageBox.alert("请求异常！");
  }
});  
           //  window.location.href="view/customer/CheckCustomer_General.jsp?custId="+selectedCustId;
        }   
        grid.addListener('rowdblclick',checkMyCustomer);
/*grid.on('rowdblclick',function(){ window.location.href="view/customer/CheckCustomer_General.jsp" });*/
        
        
function addGuarantor(){
//	addCustListStore.reload();
	Ext.getCmp('addGuarantorForm').form.reset(); 
	Ext.getCmp("guarantorId").enable();
	Ext.getCmp("addGuarantorWin").buttons[0].handler = function(){
		if(addGuarantorForm.form.isValid()){
		addGuarantorForm.form.doAction('submit', { 
			url : 'obligation/addGuarantor.do', 
			method : 'post', 
			success:function(response){
				Ext.getCmp('addGuarantorWin').hide();
				Ext.Msg.alert('提示', '保存成功！'); 
				addCustListStore.reload();
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
			} 
		});  
	}
	}; 
	Ext.getCmp("addGuarantorWin").show(); 
	}
        
        
}); 